package rule06;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * @author ChangLiang
 * @date 2020/3/16
 */
public class PersonV2 {
    /**
     * 静态的好处是：每一个类只会创建一次
     */
    private static Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    private static Date start;
    private static Date end;

    static{
        gmtCal.set(1946, Calendar.JANUARY, 1, 0, 0, 0);
        start = gmtCal.getTime();

        gmtCal.set(1965, Calendar.JANUARY, 1, 0, 0, 0);
        end = gmtCal.getTime();
    }

    private Date birthDate;

    public void setBirthDate(Date birthDate) {
        this.birthDate = birthDate;
    }

    /**
     * 每次调用一次，都创建一个Calendar对象 解决方法就是将其变成静态的
     * 此人是否出生在baby高峰期
     * @return
     */
    public boolean isBabyBoomer() {
        return this.birthDate.compareTo(start) >= 0 && this.birthDate.compareTo(end) <= 0;
    }
}
